/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package database;

import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;
import others.*;
import security.*;

/**
 *
 * @author Comarch
 */
public class Main {
    public static ArrayList<User>L;
    static String path="database";
    public static void main(String[]args){
     create();
     
     Scanner in = new Scanner(System.in);
        while (1>0){
        String s = in.nextLine();
        if (s.equals("list")) {
            for (User u : L) System.out.print(u.name + " "+u.pass+"\n");
           }
        
        if (s.equals("add")) {
        String a,b;
        a = in.nextLine();
        b = in.nextLine();
        User u = new User();
        u.name=a;
        u.pass=MD5.getMD5(b);
        L.add(u);
        }
        
        if (s.equals("load")) create();
        if (s.equals("save")) save();
        if (s.equals("delete")){
            String a;
            a=in.nextLine();
            User u = new User();
            u.name=a;
            L.remove(u);
            }
        }
    }
     
    

    public static void create() {
        File f = new File(path);
        if (f.exists()==false) L = new ArrayList<User>();
        else L = (ArrayList<User>) Serializator.loadObject(path);
}
    
    public static void save(){
    Serializator.saveObject(L, path);
    }
}
